package com.yz.common.utils;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;

import java.security.MessageDigest;

public class ShiroUtils {
    /**  加密算法 */
    public final static String hashAlgorithmName = "SHA-256";
    /**  循环次数 */
    public final static int hashIterations = 16;
    public static String sha256(String password, String salt) {
        MessageDigest digest = DigestUtils.getSha256Digest();
        if(salt!=null){
            digest.update(salt.getBytes());
        }
        byte[] rs = digest.digest(password.getBytes());
        int iterations = 16 - 1;
        for (int i = 0; i < iterations; i++) {
            digest.reset();
            rs = digest.digest(rs);
        }
        return  Hex.encodeHexString(rs);
    }
}
